#!/bin/bash
source src/conf/config.conf
cd $tftp_dir

mirror=http://archive.ubuntu.com/ubuntu/dists
echo " Downloading Ubuntu Precise..."

wget -c -q $mirror/precise/main/installer-i386/current/images/netboot/netboot.tar.gz -O ubuntu-precise-i386.tar.gz
wget -c -q $mirror/precise/main/installer-amd64/current/images/netboot/netboot.tar.gz -O ubuntu-precise-amd64.tar.gz

echo " Downloading Ubuntu Raring..."

wget -c -q $mirror/raring/main/installer-i386/current/images/netboot/netboot.tar.gz -O ubuntu-raring-i386.tar.gz
wget -c -q $mirror/raring/main/installer-amd64/current/images/netboot/netboot.tar.gz -O ubuntu-raring-amd64.tar.gz

echo " Downloading Ubuntu Oneiric..."

wget -c -q $mirror/oneiric/main/installer-i386/current/images/netboot/netboot.tar.gz  -O ubuntu-oneiric-i386.tar.gz
wget -c -q $mirror/oneiric/main/installer-amd64/current/images/netboot/netboot.tar.gz -O ubuntu-oneiric-amd64.tar.gz

echo " Downloading Ubuntu Hardy..."

wget -c -q $mirror/hardy/main/installer-amd64/current/images/netboot/netboot.tar.gz -O ubuntu-hardy-amd64.tar.gz
wget -c -q $mirror/hardy/main/installer-i386/current/images/netboot/netboot.tar.gz -O ubuntu-hardy-i386.tar.gz

echo " Downloading Ubuntu Lucid..."

wget -c -q $mirror/lucid/main/installer-amd64/current/images/netboot/netboot.tar.gz -O ubuntu-lucid-amd64.tar.gz
wget -c -q $mirror/lucid/main/installer-i386/current/images/netboot/netboot.tar.gz -O ubuntu-lucid-i386.tar.gz

echo " Downloading Ubuntu Quantal..."

wget -c -q $mirror/quantal/main/installer-amd64/current/images/netboot/netboot.tar.gz -O ubuntu-quantal-amd64.tar.gz
wget -c -q $mirror/quantal/main/installer-i386/current/images/netboot/netboot.tar.gz -O ubuntu-quantal-i386.tar.gz

echo " Downloading Ubuntu Saucy..."

wget -c -q $mirror/saucy/main/installer-amd64/current/images/netboot/netboot.tar.gz -O ubuntu-saucy-amd64.tar.gz
wget -c -q $mirror/saucy/main/installer-i386/current/images/netboot/netboot.tar.gz -O ubuntu-saucy-i386.tar.gz


for DIST in hardy lucid oneiric precise quantal raring saucy; do
    mkdir -p "./_ubuntu-installer/${DIST}"
    for ARCH in i386 amd64; do
        tar -xzvf "ubuntu-${DIST}-${ARCH}".tar.gz ./ubuntu-installer/
mv "./ubuntu-installer/${ARCH}/" "./_ubuntu-installer/${DIST}/"

done
done
 rm -r ./ubuntu-installer/
mkdir tars
mv ubuntu*.tar.gz tars/
yes | cp -Rv _ubuntu-installer/* LINUX/ubuntu/
rm -r _ubuntu-installer
done
done


## Menu - Ubuntu

touch pxelinux.cfg/ubuntu-install.cfg
cat >> pxelinux.cfg/ubuntu-install.cfg << EOF
default vesamenu.c32
prompt 0
timeout 0
menu title ubuntu Installers
menu include pxelinux.cfg/graphics.conf
MENU BACKGROUND pxelinux.cfg/background.png

EOF

for DIST in  hardy lucid oneiric precise quantal raring saucy; do
    for ARCH in i386 amd64; do
        echo "label Install ubuntu ${DIST} ${ARCH}"
        echo "      menu label ubuntu ${DIST} ${ARCH}"
        echo "      kernel LINUX/ubuntu/${DIST}/${ARCH}/linux"
         echo "      append initrd= LINUX/ubuntu/${DIST}/${ARCH}/initrd.gz ks=http://pxe.sytes.net/answerfiles/kickstart/ubuntu-ks.cfg preseed/url=http://pxe.sytes.net/answerfiles/preseed/ubuntu-preseed.cfg"

echo " "
	echo " TEXT HELP"
       echo "  Install Ubuntu Linux  ${DIST} ${ARCH}"
        echo " ENDTEXT"


        echo
    done
done >> pxelinux.cfg/ubuntu-install.cfg

for DIST in  hardy lucid oneiric precise quantal raring saucy; do
  ls -lisa "LINUX/ubuntu/${DIST}/${ARCH}"
    for ARCH in i386 amd64; do
      rm -r "LINUX/ubuntu/${DIST}/${ARCH}/pxelinux.0" 
	rm -r "LINUX/ubuntu/${DIST}/${ARCH}/pxelinux.cfg"
rm -r "LINUX/ubuntu/${DIST}/${ARCH}/boot-screens/"

 done 
done

unset mirror 
